/*
 * SyntacticParser.h
 * VB Script Analyzer
 * @author Gregoire JACOB (gregoire.jacob@orange-ftgroup.com)
 * @date 27/08/2008
 * @version 1.1
 * Analyse the syntax of the script in order to recover the different
 * procedures, functions, their arguments, managers and variables
 */


/**
 * detectStringCiphering()
 * @param the script structure to update
 * @param the location of the line (main/function/procedure)
 * @param the line index at the given location
 * @return 1 if string ciphering is detected else 0
 * Detects the string ciphering each time a knwon object is created 
 * with an intermediate call to decipher its name. Once detected, builds
 * a deciphering script that can be called using decipherString();
 */
int detectStringCiphering(struct SCRIPT * script, struct TYPING * types,
						   unsigned long location, int lineindex, FILE * scriptf); 
void decipherString(struct SCRIPT * script, char * call, int nbargs); 


/**
 * extractManagers()
 * @param the structure hosting the found managers
 * @param the line structure to process
 * @return 1 if a manager has been extracted otherwise 0
 * Analyzes a given line to find occurence of file, shell, network managers
 */
int extractFileSystemObject(struct MANAG_ENTRY * managers, struct LINE * line);
int extractShellObject(struct MANAG_ENTRY * managers, struct LINE * line);
int extractNetworkObject(struct MANAG_ENTRY * managers, struct LINE * line);
int extractMailObject(struct MANAG_ENTRY * managers, struct LINE * line);
int extractManagers(struct MANAG_ENTRY * managers, struct LINE * line);

/**
 * parseVariables()
 * @param the line structure to process
 * @param the tables of recovered variables
 * Analyzes a given line of declaration for variables (dim)
 */
int parseVariables(struct MANAG_ENTRY * managers, struct TYPING * types,
				   struct LINE * line, char * variables [NAME_MAX_LENGTH]);


/**
 * localizeFuncAndProc()
 * @param structure hosting the recovered information about functions/procedures
 * @param the script file to analyze 
 * Analyzes a given file to localize functions/procedures (pointer positions)
 * @warning File pointer should be at position 0
 * When a function or a procedure is found, addFunction or addProcedure is called 
 * to initialize a new function or procedure entry in sthe script structure. 
 */
void localizeFuncAndProc(struct SCRIPT * script, struct TYPING * types, FILE * scriptf);
void addFunction(struct SCRIPT * script, struct TYPING * types, FILE * scriptf);
void addProcedure(struct SCRIPT * script, struct TYPING * types, FILE * scriptf);

/**
 * analyzeMain()
 * @param structure hosting the recovered information about the script syntax
 * @param the script file to analyze 
 * Analyzes a given file to recover vbs syntactic information.
 * @warning Analysis should be launched AFTER having localised functions and procedures
 */
void analyzeMain(struct SCRIPT * script, struct TYPING * types, FILE * scriptf);

/**
 * parseFunction/Procedure()
 * @param the index of the function to parse
 * @param structure hosting the recovered information about functions/procedures
 * @param structure hosting the typing information about the script
 * @param the script file to analyze 
 * Analyzes a given file to recover a function/procedure syntax
 * @warning Analysis starts from the current file pointer location
 */
void parseFunction(int findex, struct SCRIPT * script, 
				   struct TYPING * types, FILE * scriptf);
void parseProcedure(int pindex, struct SCRIPT * script,
                    struct TYPING * types, FILE * scriptf);
